package com.tony.mindwarning.service.impl;

import com.tony.mindwarning.mpper.OutbroundMapper;
import com.tony.mindwarning.mpper.ProductMapper;
import com.tony.mindwarning.pojo.Outbround;
import com.tony.mindwarning.pojo.Product;
import com.tony.mindwarning.service.OutbroundService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: OutbroundServiceImpl
 * @Auther: 皮蛋布丁
 * @Date: 2021/04/11/20:38
 * @Description:
 */
@Service
public class OutbroundServiceImpl implements OutbroundService {

    @Resource
    OutbroundMapper outbroundMapper;
    @Resource
    ProductMapper productMapper;

    @Override
    @Transactional
    public int outbround(Outbround outbround,int userId) {
        Product p=new Product();
        p.setPid(outbround.getPid());
        p.setPcount(outbround.getOutcount());
        //出库修改库存
        int count = productMapper.updateProductCount(p,userId);
        if(count>0){
            //新增出库记录
            outbroundMapper.outbround(outbround,userId);
        }
        return 1;
    }

    @Override
    public int getTotlCount() {
        return outbroundMapper.getTotlCount();
    }

    @Override
    public List<Outbround> getOutbroundByPage(Map<String, Object> map) {
        return outbroundMapper.getOutbroundByPage(map);
    }

    @Override
    public int deleteOutbroundRecord(int id,int userId) {
        return outbroundMapper.deleteOutbroundRecord(id,userId);
    }
}
